package com.mpyy.dao.everyday;

import com.mpyy.pojo.AdvancePayment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @version 1.0
 * @Description FinanceDaoInter
 * Author yyjc
 * @Date 2022-03-18 21:14
 */
@Mapper
@Repository
public interface FinanceDaoInter {
    @Select("SELECT empName,a.accName,b.advPayMoney,b.advPayComment FROM bank_accounts a,advance_payment b,employee_info c WHERE a.accId=b.accId AND b.empId=c.empId")
    public List<AdvancePayment> all();

    @Select(" SELECT salOrdId,advPayDate,salOrdReceivable,empName,empName FROM sale_order a,advance_payment b, bank_accounts c,employee_info d WHERE a.empId=b.empId AND b.accId=c.accId AND b.empId=d.empId AND d.empName=#{empName} AND advPayDate BETWEEN #{start} AND #{end}")
    public List<AdvancePayment> empl(@Param("empName") String empName, @Param("start") String start, @Param("end") String end);

    @Select("SELECT purStoId,purStoDate,purStoPayable,empName,supName FROM purchase_stock a,employee_info b,supplier_info c WHERE a.empId=b.empId AND a.supId=c.supId AND b.empName=#{empName} AND purStoDate BETWEEN #{start} AND #{end}")
    public List<AdvancePayment> bank(@Param("empName") String empName, @Param("start") String start, @Param("end") String end);

    @Select(" SELECT advPayDate,advPayId,advPayMoney,advPayMoney,empName,empName FROM advance_payment a,employee_info b WHERE a.empId=b.empId")
    public List<AdvancePayment> adv();

    @Select("SELECT purRetId,purRetDate,purRetRealRefund,empName,supName FROM purchase_return a,employee_info b,supplier_info c WHERE a.empId=b.empId AND a.supId=c.supId AND b.empName=#{empName} AND purRetDate BETWEEN #{start} AND #{end}")
    @Results(value = {
            @Result(column = "purRetId",property = "purStoId"),
            @Result(column = "purRetDate",property = "purStoDate"),
            @Result(column = "purRetRealRefund",property = "purStoPayable")
    })
    public List<AdvancePayment> purReturn(@Param("empName") String empName, @Param("start") String start, @Param("end") String end);

    @Select("SELECT accName,advPayMoney,empName,advPayComment FROM advance_payment a,bank_accounts b,employee_info c WHERE a.accId=b.accId AND a.empId=c.empId")
    public List<AdvancePayment> gu();
    @Update("UPDATE advance_payment a,bank_accounts b SET advPayMoney=advPayMoney+#{capital} WHERE a.accId=b.accId AND accName=#{accName}")
    public int insertbank(@Param("capital")String capital,@Param("accName") String accName);

    @Update("UPDATE advance_payment a,bank_accounts b SET advPayMoney=advPayMoney-#{capital} WHERE a.accId=b.accId AND accName=#{accName}")
    public int reducebank(@Param("capital") String capital,@Param("accName") String accName);
}
